package com.yiyang.controller;

import com.yiyang.domain.Result;
import com.yiyang.domain.ResultPage;
import com.yiyang.domain.dto.BedDetailsDto;
import com.yiyang.domain.po.BedDetails;
import com.yiyang.domain.vo.BedDetailsVo;
import com.yiyang.service.BedDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


@RestController
@RequestMapping("/beddetails")
@Slf4j
@Api(tags = "床位详情相关接口")
// @CrossOrigin("*")
public class BedDetailsController {

    @Autowired
    private BedDetailsService bedDetailsService;

    @GetMapping("/listBedDetailsVoPage")
    @ApiOperation("床位详情分页带条件查询")
    public Result<ResultPage<BedDetailsVo>> listBedDetailsVoPage(@RequestParam(defaultValue = "1") Integer page,
                                                                 @RequestParam(defaultValue = "5") Integer pageSize,
                                                                 String customerName,
                                                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startDate,
                                                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endDate,
                                                                 Integer isDeleted){
        // 1.接收参数
        log.info("当前页:{},每页显示条数:{},客户名:{},开始时间:{},结束时间:{},状态:{}",page,pageSize,customerName,startDate,endDate,isDeleted);
        // 2.调用service层方法,实现业务逻辑处理
        ResultPage<BedDetailsVo> bedDetailsVoPage = bedDetailsService.listBedDetailsVoPage(page,pageSize,customerName,startDate,endDate,isDeleted);
        // 3. 响应数据给前端
        return Result.success(bedDetailsVoPage);
    }

    @PutMapping("/updateBedDetails")
    public Result updateBedDetails(@RequestBody BedDetails bedDetails){
        // 2.调用service层方法,实现业务逻辑处理
        bedDetailsService.updateBedDetails(bedDetails);
        // 3. 响应数据给前端
        return Result.success();
    }

    @PutMapping("/exchangeBed")
    public Result exchangeBed(@RequestBody BedDetailsDto bedDetailsDto){
        // 2.调用service层方法,实现业务逻辑处理
        bedDetailsService.exchangeBed(bedDetailsDto);
        // 3. 响应数据给前端
        return Result.success();
    }
}
